package com.qf.service;

import com.qf.constant.RabbitMQConstants;
import com.qf.model.StandardSubmit;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpAdmin;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

/**
 * author:z
 * time:2021/12/29 17:22
 * description:路由策略
 */
@Service(value = "router")
@Slf4j
public class RouteChainManagerImpl implements FilterChainService{

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Autowired
    private AmqpAdmin amqpAdmin;
    @Override
    public boolean strategy(StandardSubmit standardSubmit) {
        log.info("[策略模块-路由策略]开始执行！");
        //1.创建不同的运营商队列的名字
        String queueName = RabbitMQConstants.TOPIC_SMS_GATEWAY+ standardSubmit.getOperatorId();
        //2.创建队列
        amqpAdmin.declareQueue(QueueBuilder.durable(queueName).build());
        //3.将短信对象数据发送到队列中，供Gateway网关模块接收使用
        rabbitTemplate.convertAndSend(queueName,standardSubmit);
        return true;
    }
}
